//src/store/user.ts

import { defineStore } from 'pinia'

export const useUserStore = defineStore({
    id: 'user', // id必填，且需要唯一
    state: () => {
        return {
            listData: [] as todoItemItf[],
            checkAllList: []
        }
    },
    // 数据持久化
    persist: {
        enabled: true,
        strategies: [
            {
                storage: localStorage, // 持久化类型
                paths: ['listData', 'checkAllList']
            }
        ]
    },
    actions: {
        addItem(content: todoItemItf) {
            this.listData.push(content)
        },
        addCheckList(content: any) {
            this.checkAllList = content
        },
        removeItem(item: todoItemItf) {
            const i = this.listData.findIndex((m: todoItemItf) => m.content === item.content)
            const idx = this.checkAllList.findIndex((m: string) => m === item.content)
            if (i > -1) {
                this.listData.splice(i, 1)
                this.checkAllList.splice(idx, 1)
            }
        },
    }
})